package com.jf.blog.controller;

import com.jf.blog.form.blog.BlogForm;
import com.jf.blog.form.blog.BlogSearchForm;
import com.jf.blog.service.BlogService;
import com.jf.blog.service.BlogTagService;
import com.jf.blog.util.ResultJson;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 博客表 前端控制器
 * </p>
 *
 * @author JF
 * @since 2025-06-20
 */
@RestController
@RequestMapping("/blog")
@Api(tags = "博客模块")
public class BlogController {
    @Autowired
    private BlogService blogService;
    @Autowired
    private BlogTagService blogTagService;

    @GetMapping("/page")
    @ApiOperation("分页筛选")
    public ResultJson page(@RequestParam(defaultValue = "1") @ApiParam(required = true) int page, @RequestParam(defaultValue = "5") @ApiParam(required = true) int limit, BlogSearchForm form) {
        return blogService.getPage(page, limit, form);
    }

    @GetMapping("/info/{blogId}")
    @ApiOperation("博客详情")
    public ResultJson info(@PathVariable int blogId) {
        return blogService.getBlogInfo(blogId);
    }

    @PostMapping("/update")
    @ApiOperation("添加或修改博客")
    public ResultJson update(@RequestBody BlogForm form) {
        blogService.saveOrUpdate(form);
        return ResultJson.success();
    }

    @DeleteMapping("/delete")
    @ApiOperation("批量删除")
    public ResultJson delete(@RequestBody List<Integer> blogIds) {
        blogService.delete(blogIds);
        return ResultJson.success();
    }

    @PostMapping("/status/{blogId}")
    @ApiOperation("修改数据状态")
    public ResultJson status(@PathVariable int blogId) {
        blogService.updateStatus(blogId);
        return ResultJson.success();
    }

    @PostMapping("/status/blog/{blogId}")
    @ApiOperation("修改博客状态")
    public ResultJson blogStatus(@PathVariable int blogId) {
        blogService.updateBlogStatus(blogId);
        return ResultJson.success();
    }

    @GetMapping("/tag/{blogId}")
    @ApiOperation("根据博客编号查看标签")
    public ResultJson tagList(@PathVariable int blogId) {
        return blogTagService.getBlogTagByBlogId(blogId);
    }

}
